home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / System Software / U.S. System Software / System 7 Pro™ Beta 11 / Development Tools / Sample Code / Interprogram Messaging Manager / IPM MessageBoard / AddressOMini.c next >
Encoding:
C/C++ Source or Header  |  1993-06-28  |  12.0 KB  |  490 lines  |  [TEXT/MPS ]

  1. #ifndef __TYPES__
  2. #include <Types.h>
  3. #endif
  4.  
  5. #ifndef __DIALOGS__
  6. #include <Dialogs.h>
  7. #endif
  8.  
  9. #ifndef __OCE__
  10. #include <OCE.h>
  11. #endif
  12.  
  13. #ifndef __OCEAUTHDIR__
  14. #include <OCEAuthDir.h>
  15. #endif
  16.  
  17. #ifndef __OCESTANDARDDIRECTORY__
  18. #include <OCEStandardDirectory.h>
  19. #endif
  20.  
  21. #include "utils.h"
  22. #include "AddressOMini.h"
  23.  
  24.  
  25. // constants
  26. #define    kFindLayoutRsrcID        128
  27. #define    kGetDirectoriesDialog    132
  28. #define    kBrowseRadio            3
  29. #define    kFindRadio                4
  30. #define    kPanelItem                5
  31. #define    kActive                    0
  32. #define    kDimmed                    255
  33. #define    kInFront                (WindowPtr)-1L
  34. #define    kFindText                "\pFind"
  35. #define    kStopText                "\pStop"
  36. #define    kSelectText                "\pSelect"
  37. #define    kOpenText                "\pOpen"
  38.  
  39. enum {
  40.     kBrowsePanel,kFindPanel
  41. };
  42.  
  43.  
  44. // file globals
  45.  
  46. static short gPanelKind = kBrowsePanel;
  47.  
  48.  
  49. // prototypes
  50.  
  51. pascal void PanelUserItem(DialogPtr theDlg,short item);
  52. pascal Boolean PanelFilterEvent(DialogPtr theDlg,EventRecord *ev,short *itemHit);
  53. void RecalcFindButton(DialogPtr theDlg,SDPFindPanelHandle thePanel);
  54. void RecalcBrowseButton(DialogPtr theDlg,SDPPanelHandle thePanel);
  55.  
  56.  
  57. // *****************************************************************
  58. // *    CheckPanelSize
  59. // *
  60. // *    make sure the Directory Broswer "fits" into the space alloted to it
  61. // *****************************************************************
  62. void CheckPanelSize(DialogPtr dlg,Rect *panelRect,short panelItem)
  63. {
  64.     Handle iHndl;
  65.     short iType;
  66.     FontInfo fInfo;
  67.     short minWidth,minHeight,fontHeight;
  68.  
  69.  
  70.     GetDItem(dlg,panelItem,&iType,&iHndl,panelRect);
  71. // #### 
  72.     GetFontInfo(&fInfo);
  73.     minWidth = 5*fInfo.widMax + 42;
  74.     fontHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  75.     minHeight = fontHeight + 18;
  76. // #####     
  77.     minHeight = (64 > 3*fontHeight) ? (minHeight + 64) : (minHeight + 3*fontHeight);
  78.     if ((panelRect->bottom - panelRect->top) < minHeight)
  79.     {
  80.         panelRect->bottom = panelRect->top + minHeight;
  81.         SetDItem(dlg,panelItem,iType,iHndl,panelRect);
  82.     }
  83.     if ((panelRect->right - panelRect->left) < minWidth)
  84.     {
  85.         panelRect->right = panelRect->left + minWidth;
  86.         SetDItem(dlg,panelItem,iType,iHndl,panelRect);
  87.     }
  88.  
  89. }
  90.  
  91. Boolean AddressOMini(PackedDSSpecPtr *dsSpec,
  92.                                const RStringPtr *typesList,
  93.                                unsigned long typeCount,
  94.                                AuthIdentity identity,
  95.                                DirEnumChoices enumFlags,
  96.                                ConstStr255Param promptString,
  97.                                DirMatchWith matchTypeHow)
  98. {
  99.     static Boolean gHasBeenCalled = false;    // save our rli location for the next time
  100.     static PackedRLI gInitialRLI;            // we call this function
  101.     static short gDSRefNum;
  102.     
  103.     SDPPanelHandle browsePanel;
  104.     SDPFindPanelHandle findPanel;
  105.     SDPSelectionState bSelectionState;
  106.     SDPPanelState bPanelState;
  107.     SDPFindPanelState fPanelState;
  108.     OSErr err;
  109.     DialogPtr theDlg;
  110.     short iType;
  111.     Handle iHndl;
  112.     Rect iRect;
  113.     Point upLeft;
  114.     short item;
  115.     Boolean selectedRecord;
  116.     unsigned short dsSpecSize;
  117.     
  118.     // set up prompt
  119.         
  120.     if (promptString)
  121.         ParamText(promptString,nil,nil,nil);
  122.     else
  123.         ParamText("\pSelect a Record:",nil,nil,nil);
  124.  
  125.     // get the dialog
  126.     theDlg = GetNewDialog(kGetDirectoriesDialog,nil,kInFront);
  127.  
  128.     SetPort(theDlg);
  129.  
  130.     // make panels
  131.     
  132.     GetDItem(theDlg,kPanelItem,&iType,&iHndl,&iRect);
  133.     SetDItem(theDlg,kPanelItem,iType,(Handle)PanelUserItem,&iRect);
  134.  
  135.  
  136.     err = SDPNewPanel(&browsePanel,(WindowPtr)theDlg,&iRect,(gPanelKind==kBrowsePanel),
  137.                     (gPanelKind==kBrowsePanel),((gHasBeenCalled) ? & gInitialRLI : nil),
  138.                     typesList,typeCount,identity,
  139.                     enumFlags,matchTypeHow,0);    
  140.     if (err!=noErr) {
  141.         DisposeDialog(theDlg);
  142.         return false;
  143.     }
  144.         
  145.     upLeft.h = iRect.left;
  146.     upLeft.v = iRect.top;
  147.     err = SDPNewFindPanel(&findPanel,(WindowPtr)theDlg,upLeft,kFindLayoutRsrcID,
  148.                     (gPanelKind==kFindPanel),(gPanelKind==kFindPanel),typesList,
  149.                     typeCount,matchTypeHow,identity,1,kSDPFindPanelTextHasFocus,0);    
  150.     if (err!=noErr) {
  151.         SDPDisposePanel(browsePanel);
  152.         DisposeDialog(theDlg);
  153.         return false;
  154.     }
  155.  
  156.     // set up radio buttons
  157.     
  158.     if (gPanelKind==kBrowsePanel) {
  159.         SetWRefCon((WindowPtr)theDlg,(long)browsePanel);
  160.         GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
  161.         RecalcBrowseButton(theDlg,browsePanel);
  162.     }
  163.     else {
  164.         SetWRefCon((WindowPtr)theDlg,(long)findPanel);
  165.         GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
  166.         RecalcFindButton(theDlg,findPanel);
  167.     }
  168.     SetCtlValue((ControlHandle)iHndl,1);
  169.     
  170.     selectedRecord = false;
  171.     do {
  172.         ModalDialog(PanelFilterEvent,&item);
  173.         switch (item) {
  174.         
  175.             case kBrowseRadio:
  176.                 if (gPanelKind!=kBrowsePanel) {
  177.                     
  178.                     // stop any finds going on
  179.                     
  180.                     if ((**findPanel).nowFinding)
  181.                         SDPStopFind(findPanel);
  182.                     
  183.                     // reset buttons
  184.                     
  185.                     GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
  186.                     SetCtlValue((ControlHandle)iHndl,1);
  187.                     GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
  188.                     SetCtlValue((ControlHandle)iHndl,0);
  189.                     
  190.                     // switch the panels
  191.  
  192.                     SDPEnableFindPanel(findPanel,false);
  193.                     SDPHideFindPanel(findPanel);
  194.                     SetWRefCon((WindowPtr)theDlg,(long)browsePanel);
  195.                     gPanelKind = kBrowsePanel;
  196.                     SDPShowPanel(browsePanel);
  197.                     SDPEnablePanel(browsePanel,true);
  198.                     
  199.                     // udpate ok button
  200.                     
  201.                     RecalcBrowseButton(theDlg,browsePanel);
  202.                     
  203.             }
  204.                 break;
  205.                 
  206.             case kFindRadio:
  207.                 if (gPanelKind!=kFindPanel) {
  208.                 
  209.                     // reset buttons
  210.                     
  211.                     GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
  212.                     SetCtlValue((ControlHandle)iHndl,1);
  213.                     GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
  214.                     SetCtlValue((ControlHandle)iHndl,0);
  215.  
  216.                     // switch the panels
  217.                     
  218.                     SDPEnablePanel(browsePanel,false);
  219.                     SDPHidePanel(browsePanel);
  220.                     SetWRefCon((WindowPtr)theDlg,(long)findPanel);
  221.                     gPanelKind = kFindPanel;
  222.                     SDPShowFindPanel(findPanel);
  223.                     SDPEnableFindPanel(findPanel,true);
  224.                     
  225.                     // update ok button
  226.                     
  227.                     RecalcFindButton(theDlg,findPanel);
  228.                 }
  229.                 break;
  230.                 
  231.             case ok:
  232.                 if (gPanelKind==kBrowsePanel) {
  233.                 
  234.                     // browse panel ok hit
  235.                     
  236.                     SDPGetPanelSelectionState(browsePanel,&bSelectionState);
  237.                     if (bSelectionState==kSDPRecordSelected || bSelectionState==kSDPRecordAliasSelected)
  238.                         selectedRecord = true;
  239.                     else
  240.                         SDPOpenSelectedItem(browsePanel,&bPanelState);
  241.                 }
  242.                 else {
  243.                 
  244.                     // find panel ok hit
  245.                     
  246.                     SDPGetFindPanelState(findPanel,&fPanelState);
  247.                     if ((**findPanel).nowFinding) {                    // stop the find
  248.                         SDPStopFind(findPanel);
  249.                         GetDItem(theDlg,ok,&iType,&iHndl,&iRect);
  250.                         if (fPanelState&kSDPItemIsSelectedMask)
  251.                             SetCTitle((ControlHandle)iHndl,kSelectText);
  252.                         else
  253.                             SetCTitle((ControlHandle)iHndl,kFindText);
  254.                     }
  255.                     else if (fPanelState&kSDPItemIsSelectedMask)        // select the item and exit
  256.                         selectedRecord = true;
  257.                     else if (fPanelState&kSDPFindTextExistsMask) {        // start a find
  258.                         SDPStartFind(findPanel);
  259.                     }
  260.  
  261.                 }
  262.                 break;
  263.         }
  264.     }
  265.     while (!selectedRecord && item!=cancel);
  266.     
  267.     // get selected record, if we have one
  268.     
  269.     if (selectedRecord) {
  270.         if (gPanelKind==kBrowsePanel)
  271.             err = SDPGetPanelSelectionSize(browsePanel,&dsSpecSize);
  272.         else
  273.             err = SDPGetFindPanelSelectionSize(findPanel,&dsSpecSize);
  274.         if (err==noErr) {
  275.             *dsSpec = (PackedDSSpecPtr)NewPtr(dsSpecSize);
  276.             if (MemError()==noErr) {
  277.                 if (gPanelKind==kBrowsePanel)
  278.                     err = SDPGetPanelSelection(browsePanel,*dsSpec);
  279.                 else
  280.                     err = SDPGetFindPanelSelection(findPanel,*dsSpec);
  281.             }
  282.             else err = MemError();
  283.         }
  284.     }
  285.     
  286.     // get info out for next call
  287.     
  288.     gHasBeenCalled = true;
  289.     SDPGetPath(browsePanel,&gInitialRLI,&gDSRefNum);
  290.     
  291.     // release stuff from memory
  292.     
  293.     SDPDisposePanel(browsePanel);
  294.     SDPDisposeFindPanel(findPanel);
  295.     DisposeDialog(theDlg);
  296.     
  297.     return selectedRecord;
  298. }
  299.  
  300.  
  301. pascal void PanelUserItem(DialogPtr theDlg,short item)
  302. {
  303.     #pragma unused (item)
  304.     long thePanel;
  305.     
  306.     thePanel = GetWRefCon((WindowPtr)theDlg);
  307.     
  308.     if (gPanelKind==kBrowsePanel)
  309.         SDPUpdatePanel((SDPPanelHandle)thePanel,nil);
  310.     else
  311.         SDPUpdateFindPanel((SDPFindPanelHandle)thePanel,nil);
  312. }
  313.  
  314.  
  315. pascal Boolean PanelFilterEvent(DialogPtr theDlg,EventRecord *ev,short *itemHit)
  316. {
  317.     char theChar;
  318.     long thePanel;
  319.     SDPPanelState bPanelState;
  320.     SDPFindPanelState fPanelState;
  321.     SDPFindPanelResult fPanelResult;
  322.     short iType;
  323.     ControlHandle iHndl;
  324.     Rect iRect;
  325.     Str255 cTitle;
  326.     OSErr err;
  327.     
  328.     // check for user cancel
  329.     
  330.     if (ev->what==keyDown) {
  331.         theChar = ev->message & charCodeMask;
  332.         if ((theChar==0x1b) || (theChar=='.' && ev->modifiers&cmdKey)) {
  333.             *itemHit = cancel;
  334.             FlashControl(theDlg,cancel);
  335.             return true;
  336.         }
  337.     }
  338.     
  339.     if (ev->what != updateEvt) {
  340.     
  341.         thePanel = GetWRefCon((WindowPtr)theDlg);
  342.         
  343.         if (gPanelKind==kBrowsePanel) {
  344.         
  345.             // browse panels
  346.             
  347.             RecalcBrowseButton(theDlg,(SDPPanelHandle)thePanel);
  348.             
  349.             SDPPanelEvent((SDPPanelHandle)thePanel,ev,&bPanelState);
  350.             if (bPanelState==kSDPSelectedAnItem) {
  351.                 *itemHit = ok;
  352.                 return true;
  353.             }
  354.         }
  355.         else {
  356.         
  357.             // find panels
  358.             
  359.             GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
  360.             GetCTitle(iHndl,cTitle);
  361.             
  362.             SDPFindPanelEvent((SDPFindPanelHandle)thePanel,ev,&fPanelResult);
  363.             switch (fPanelResult) {
  364.                 case kSDPSelectedAFindItem:
  365.                     FlashControl(theDlg,ok);
  366.                     *itemHit = ok;
  367.                     return true;
  368.                     break;
  369.                 case kSDPFindSelectionChanged:
  370.                 case kSDPTextStateChanged:
  371.                 case kSDPFocusChanged:
  372.                 case kSDPSelectionAndFocusChanged:
  373.                 case kSDPSelectionAndMenuChanged:
  374.                     GetCTitle(iHndl,cTitle);
  375.                     if (EqualString(cTitle,kStopText,true,true))
  376.                         FlashControl(theDlg,ok);
  377.                     RecalcFindButton(theDlg,(SDPFindPanelHandle)thePanel);
  378.                     break;
  379.                 case kSDPProcessedFind:
  380.                     if ((**(SDPFindPanelHandle)thePanel).nowFinding) {
  381.                         GetCTitle(iHndl,cTitle);
  382.                         if (!EqualString(cTitle,kStopText,true,true)) {
  383.                             FlashControl(theDlg,ok);
  384.                             SetCTitle((ControlHandle)iHndl,kStopText);
  385.                         }
  386.                     }
  387.                     break;
  388.                 case kSDPFindCompleted:
  389.                     err = SDPGetFindPanelState((SDPFindPanelHandle)thePanel,&fPanelState);
  390.                     if ((err==noErr) && (fPanelState&kSDPItemIsSelectedMask))
  391.                         SetCTitle((ControlHandle)iHndl,kSelectText);
  392.                     else
  393.                         SetCTitle((ControlHandle)iHndl,kFindText);
  394.                     break;
  395.             }
  396.         }
  397.     }
  398.     else
  399.         MyDrawDefaultButtonOutline(theDlg,ok);
  400.     
  401.     return false;
  402. }
  403.  
  404.  
  405.  
  406. void RecalcBrowseButton(DialogPtr theDlg,SDPPanelHandle thePanel)
  407. {
  408.     SDPPanelState panelState;
  409.     short iType;
  410.     ControlHandle iHndl;
  411.     Rect iRect;
  412.     Str255 cTitle;
  413.     
  414.     SDPGetPanelSelectionState(thePanel,&panelState);
  415.     GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
  416.     GetCTitle(iHndl,cTitle);
  417.  
  418.     switch (panelState) {
  419.         case kSDPNothingSelected:
  420.         case kSDPLockedContainerSelected:
  421.             if ((**iHndl).contrlHilite!=kDimmed) {
  422.                 HiliteControl(iHndl,kDimmed);
  423.                 MyDrawDefaultButtonOutline(theDlg,ok);
  424.             }
  425.             if (!EqualString(cTitle,kOpenText,true,true))
  426.                 SetCTitle(iHndl,kOpenText);
  427.             break;
  428.         case kSDPContainerSelected:
  429.         case kSDPContainerAliasSelected:
  430.             if ((**iHndl).contrlHilite!=kActive) {
  431.                 HiliteControl(iHndl,kActive);
  432.                 MyDrawDefaultButtonOutline(theDlg,ok);
  433.             }
  434.             if (!EqualString(cTitle,kOpenText,true,true))
  435.                 SetCTitle(iHndl,kOpenText);
  436.             break;
  437.         case kSDPRecordSelected:
  438.         case kSDPRecordAliasSelected:
  439.             if ((**iHndl).contrlHilite!=kActive) {
  440.                 HiliteControl(iHndl,kActive);
  441.                 MyDrawDefaultButtonOutline(theDlg,ok);
  442.             }
  443.             if (!EqualString(cTitle,kSelectText,true,true))
  444.                 SetCTitle(iHndl,kSelectText);
  445.             break;
  446.     }        
  447. }
  448.  
  449.  
  450. void RecalcFindButton(DialogPtr theDlg,SDPFindPanelHandle thePanel)
  451. {
  452.     Str255 cTitle;
  453.     short iType;
  454.     ControlHandle iHndl;
  455.     Rect iRect;
  456.     SDPFindPanelState fPanelState;
  457.     OSErr err;
  458.     
  459.     GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
  460.     err = SDPGetFindPanelState(thePanel,&fPanelState);
  461.     if (err==noErr) {
  462.         switch (fPanelState) {
  463.             case kSDPItemIsSelectedMask:
  464.             case (kSDPItemIsSelectedMask|kSDPFindTextExistsMask):
  465.                 if ((**iHndl).contrlHilite!=kActive) {
  466.                     HiliteControl(iHndl,kActive);
  467.                     MyDrawDefaultButtonOutline(theDlg,ok);
  468.                 }    
  469.                 if (!EqualString(cTitle,kSelectText,true,true))
  470.                     SetCTitle(iHndl,kSelectText);
  471.                 break;
  472.             case kSDPFindTextExistsMask:
  473.                 if ((**iHndl).contrlHilite!=kActive) {
  474.                     HiliteControl(iHndl,kActive);
  475.                     MyDrawDefaultButtonOutline(theDlg,ok);
  476.                 }    
  477.                 if (!EqualString(cTitle,kFindText,true,true))
  478.                     SetCTitle(iHndl,kFindText);
  479.                 break;
  480.             default:
  481.                 if ((**iHndl).contrlHilite!=kDimmed) {
  482.                     HiliteControl(iHndl,kDimmed);
  483.                     MyDrawDefaultButtonOutline(theDlg,ok);
  484.                 }    
  485.                 if (!EqualString(cTitle,kFindText,true,true))
  486.                     SetCTitle(iHndl,kFindText);
  487.                 break;
  488.         }
  489.     }
  490. }